//
//  CZQCustomNavView.m
//  StylisticCircle
//
//  Created by zhiqiang chen on 2018/7/16.
//  Copyright © 2018年 zongquankeji. All rights reserved.
//

#import "CZQCustomNavView.h"

@implementation CZQCustomNavView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        /**
         背景图
         */
        UIImageView *bgView = [[UIImageView alloc]init];
        bgView.image = [UIImage imageNamed:@"person_bg"];
        self.bgView = bgView;
        [self addSubview:bgView];
        
        /**
         返回
         */
        UIButton *popBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [popBtn setImage:@"icon_return"];
        [popBtn addTarget:self action:@selector(pop)];
        [self addSubview:popBtn];
        self.popBtn = popBtn;
        
        
        /**
         title
         */
        UILabel *titleLable = [UILabel new];
        titleLable.font = kFont17;
        titleLable.textColor = CSWhiteColor;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        
        /**
         right
         */
        UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        rightBtn.titleLabel.font = kFont16;
        [rightBtn setTitleColor:CSWhiteColor];
        [rightBtn setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
        rightBtn.hidden = YES;
        [self addSubview:rightBtn];
        self.rightBtn = rightBtn;
        
        [self setConstraints];
        
    }
    return self;
}

-(void)setConstraints
{
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
    }];
    
    [self.popBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(AdaptStatusBar);
        make.left.mas_equalTo(self).offset(0);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(56);
        
    }];
    
    [self.rightBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(AdaptStatusBar);
        make.right.mas_equalTo(self).offset(-5);
        make.height.mas_equalTo(44);
        
    }];
    
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(AdaptStatusBar);
        make.centerX.mas_equalTo(self);
        make.height.mas_equalTo(44);
        
    }];
    
}
-(void)pop
{
    [self.viewController.navigationController popViewControllerAnimated:YES];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
